﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using DB;

using System.Data;
using System.Collections;

namespace Userslib
{
    /*
     * Each Race has certain units, this class retreives those from the webservice for a gives race.
     */
    public class Units : Races
    {
        private Dictionary<String, int> UnitSpeedDict = new Dictionary<string, int>();
        private Dictionary<String, localhost.Units> UnitDict = new Dictionary<string, localhost.Units>();
        private Dictionary<String, int> AttackingUnits = new Dictionary<string, int>();


        public Units(String Race)
        {
            try
            {
                if (Races.isValidRace(Race))
                {

                    localhost.GetData WebService = new localhost.GetData();
                    var x = from localhost.Units Unit in WebService.Get_Units(Race) orderby Unit.Unit_ID ascending select Unit;
                    UnitDict = x.ToDictionary(u => u.Unit_Name);
                    var s = from Unit in UnitDict select new { Name = Unit.Value.Unit_Name, Speed = Unit.Value.Unit_Speed };
                    UnitSpeedDict = s.ToDictionary(u => u.Name, u => u.Speed);

                    var a = this.UnitDict.Where(u => u.Value.Funct == 'A' && u.Value.Loot > 0);
                    AttackingUnits = a.ToDictionary(u => u.Value.Unit_Name, u => u.Value.Unit_ID);
                }
            }
            catch (RaceException exc)
            {
                throw exc;
            }
            catch (Exception exc)
            {

            }

        }

        public Dictionary<String,int> getAttackingUnits(){
            //?
            return this.AttackingUnits;

        }

        public Dictionary<String, int> GetSpeedUnits()
        {
            return this.UnitSpeedDict;
        }
        
    }
}
